## 游戏事件常量定义
## 使用类和常量组织游戏事件，避免硬编码字符串
## 
## 使用方式:
## MessageCenter.send(self, GameEvents.Player.DIED, data)
## MessageCenter.subscribe(self, GameEvents.UI.SCORE_UPDATED, callback)

class_name GameEvents

# ========================================
# 玩家相关事件
# ========================================
class Player:
	# 生命周期事件
	const SPAWNED = "player.spawned"              # 玩家生成
	const DIED = "player.died"                    # 玩家死亡
	const RESPAWNED = "player.respawned"          # 玩家重生
	
	# 状态变化事件
	const HEALTH_CHANGED = "player.health_changed"        # 血量变化
	const MANA_CHANGED = "player.mana_changed"            # 魔法值变化
	const STAMINA_CHANGED = "player.stamina_changed"      # 体力值变化
	const LEVEL_UP = "player.level_up"                    # 升级
	
	# 战斗事件
	const ATTACKED = "player.attacked"            # 攻击
	const DAMAGED = "player.damaged"              # 受伤
	const HEALED = "player.healed"                # 治疗
	const BLOCKED = "player.blocked"              # 格挡
	const DODGED = "player.dodged"                # 闪避
	
	# 移动事件
	const MOVED = "player.moved"                  # 移动
	const JUMPED = "player.jumped"                # 跳跃
	const LANDED = "player.landed"                # 落地
	const DASHED = "player.dashed"                # 冲刺
	
	# 道具事件
	const ITEM_COLLECTED = "player.item_collected"        # 收集道具
	const ITEM_USED = "player.item_used"                  # 使用道具
	const WEAPON_EQUIPPED = "player.weapon_equipped"      # 装备武器
	const ARMOR_EQUIPPED = "player.armor_equipped"        # 装备护甲


# ========================================
# UI 相关事件
# ========================================
class UI:
	# 界面显示/隐藏
	const MENU_OPENED = "ui.menu_opened"
	const MENU_CLOSED = "ui.menu_closed"
	const DIALOG_OPENED = "ui.dialog_opened"
	const DIALOG_CLOSED = "ui.dialog_closed"
	const INVENTORY_OPENED = "ui.inventory_opened"
	const INVENTORY_CLOSED = "ui.inventory_closed"
	
	# 数据更新
	const SCORE_UPDATED = "ui.score_updated"
	const GOLD_UPDATED = "ui.gold_updated"
	const HEALTH_BAR_UPDATED = "ui.health_bar_updated"
	const MANA_BAR_UPDATED = "ui.mana_bar_updated"
	
	# 提示信息
	const NOTIFICATION_SHOWN = "ui.notification_shown"
	const TOOLTIP_SHOWN = "ui.tooltip_shown"
	const TOOLTIP_HIDDEN = "ui.tooltip_hidden"


# ========================================
# 游戏流程事件
# ========================================
class Game:
	# 游戏状态
	const STARTED = "game.started"
	const PAUSED = "game.paused"
	const RESUMED = "game.resumed"
	const GAME_OVER = "game.game_over"
	const VICTORY = "game.victory"
	
	# 关卡相关
	const LEVEL_LOADED = "game.level_loaded"
	const LEVEL_COMPLETED = "game.level_completed"
	const LEVEL_FAILED = "game.level_failed"
	const CHECKPOINT_REACHED = "game.checkpoint_reached"
	
	# 存档相关
	const GAME_SAVED = "game.saved"
	const GAME_LOADED = "game.loaded"
	const AUTOSAVE = "game.autosave"


# ========================================
# 敌人相关事件
# ========================================
class Enemy:
	# 生命周期
	const SPAWNED = "enemy.spawned"
	const DIED = "enemy.died"
	const DESPAWNED = "enemy.despawned"
	
	# 战斗
	const ATTACKED = "enemy.attacked"
	const DAMAGED = "enemy.damaged"
	const ALERTED = "enemy.alerted"              # 警戒
	const AGGRO = "enemy.aggro"                  # 仇恨
	
	# 状态
	const STATE_CHANGED = "enemy.state_changed"
	const STUNNED = "enemy.stunned"              # 眩晕
	const FROZEN = "enemy.frozen"                # 冰冻
	const BURNING = "enemy.burning"              # 燃烧


# ========================================
# 音频相关事件
# ========================================
class Audio:
	# 音乐
	const MUSIC_STARTED = "audio.music_started"
	const MUSIC_STOPPED = "audio.music_stopped"
	const MUSIC_VOLUME_CHANGED = "audio.music_volume_changed"
	
	# 音效
	const SFX_PLAYED = "audio.sfx_played"
	const SFX_VOLUME_CHANGED = "audio.sfx_volume_changed"
	
	# 语音
	const VOICE_STARTED = "audio.voice_started"
	const VOICE_STOPPED = "audio.voice_stopped"


# ========================================
# 系统事件
# ========================================
class System:
	# 设置
	const SETTINGS_CHANGED = "system.settings_changed"
	const LANGUAGE_CHANGED = "system.language_changed"
	const RESOLUTION_CHANGED = "system.resolution_changed"
	const FULLSCREEN_TOGGLED = "system.fullscreen_toggled"
	
	# 输入
	const INPUT_MODE_CHANGED = "system.input_mode_changed"  # 键鼠/手柄切换
	const CONTROLS_REMAPPED = "system.controls_remapped"
	
	# 性能
	const FPS_CHANGED = "system.fps_changed"
	const QUALITY_CHANGED = "system.quality_changed"


# ========================================
# 成就系统事件
# ========================================
class Achievement:
	const UNLOCKED = "achievement.unlocked"
	const PROGRESS_UPDATED = "achievement.progress_updated"
	const ALL_COMPLETED = "achievement.all_completed"


# ========================================
# 任务系统事件
# ========================================
class Quest:
	const STARTED = "quest.started"
	const COMPLETED = "quest.completed"
	const FAILED = "quest.failed"
	const OBJECTIVE_UPDATED = "quest.objective_updated"
	const REWARD_CLAIMED = "quest.reward_claimed"


# ========================================
# 物品/库存事件
# ========================================
class Inventory:
	const ITEM_ADDED = "inventory.item_added"
	const ITEM_REMOVED = "inventory.item_removed"
	const ITEM_USED = "inventory.item_used"
	const ITEM_EQUIPPED = "inventory.item_equipped"
	const ITEM_UNEQUIPPED = "inventory.item_unequipped"
	const GOLD_CHANGED = "inventory.gold_changed"
	const FULL = "inventory.full"


# ========================================
# NPC 事件
# ========================================
class NPC:
	const DIALOG_STARTED = "npc.dialog_started"
	const DIALOG_ENDED = "npc.dialog_ended"
	const TRADE_STARTED = "npc.trade_started"
	const TRADE_ENDED = "npc.trade_ended"
	const QUEST_GIVEN = "npc.quest_given"


# ========================================
# 网络事件（多人游戏）
# ========================================
class Network:
	const CONNECTED = "network.connected"
	const DISCONNECTED = "network.disconnected"
	const PLAYER_JOINED = "network.player_joined"
	const PLAYER_LEFT = "network.player_left"
	const SYNC_DATA = "network.sync_data"


# ========================================
# 辅助方法
# ========================================

## 获取所有事件类别
static func get_all_categories() -> Array:
	return [
		"Player", "UI", "Game", "Enemy", "Audio",
		"System", "Achievement", "Quest", "Inventory",
		"NPC", "Network"
	]


## 验证事件名称是否存在（调试用）
static func is_valid_event(event_name: String) -> bool:
	# 这里可以添加验证逻辑
	return event_name.contains(".")


## 打印所有可用事件（调试用）
static func print_all_events() -> void:
	print("========== 可用游戏事件 ==========")
	
	print("\n[玩家事件]")
	print("  生成: ", Player.SPAWNED)
	print("  死亡: ", Player.DIED)
	print("  受伤: ", Player.DAMAGED)
	print("  ... 更多请查看源码")
	
	print("\n[UI事件]")
	print("  分数更新: ", UI.SCORE_UPDATED)
	print("  菜单打开: ", UI.MENU_OPENED)
	print("  ... 更多请查看源码")
	
	print("\n[游戏流程事件]")
	print("  游戏开始: ", Game.STARTED)
	print("  游戏暂停: ", Game.PAUSED)
	print("  关卡完成: ", Game.LEVEL_COMPLETED)
	print("  ... 更多请查看源码")
	
	print("\n===================================")


# ========================================
# 使用示例
# ========================================

## 示例：如何在游戏中使用这些事件
static func usage_example():
	print("\n========== 使用示例 ==========\n")
	
	# 示例1: 玩家死亡事件
	print("示例1: 玩家死亡")
	print("发送方（Player.gd）:")
	print('  MessageCenter.send(self, GameEvents.Player.DIED, {"score": 1000})')
	print("\n接收方（UIManager.gd）:")
	print('  MessageCenter.subscribe(self, GameEvents.Player.DIED, _on_player_died)')
	
	# 示例2: UI更新事件
	print("\n示例2: 分数更新")
	print("发送方:")
	print('  MessageCenter.send(self, GameEvents.UI.SCORE_UPDATED, {"score": new_score})')
	print("\n接收方:")
	print('  MessageCenter.subscribe(self, GameEvents.UI.SCORE_UPDATED, func(s, d):')
	print('      $ScoreLabel.text = str(d.score)')
	print('  )')
	
	# 示例3: 成就解锁
	print("\n示例3: 成就解锁")
	print("发送方:")
	print('  MessageCenter.send(self, GameEvents.Achievement.UNLOCKED, {"id": "first_kill"})')
	print("\n接收方:")
	print('  MessageCenter.subscribe(self, GameEvents.Achievement.UNLOCKED, show_achievement_popup)')
	
	print("\n==============================\n")
